<template>
  <el-dialog
    :visible="dialogVisible"
    :show-close="true"
    :close-on-click-modal="false"
    :before-close="handleClose"
    :close="handleClose"
    :class="{'mobile-dialog':showMobilePage}"
    class="small-common-dialog-size operator-dialog"
  >
    <SectionTitle title="催办说明" style="margin-bottom:12px" font-size="16px"/>
    <el-input v-model="descriptionStr" :rows="3" resize="none" type="textarea" maxlength="19" placeholder="请输入少于20字的内容" />
    <div class="dialog-footer">
      <el-button :disabled="confirmDisable" class="ok" type="primary" @click="handleConfirm">
        立即催办<i v-if="loading" class="el-icon-loading"/>
      </el-button>
      <el-button class="cancel-btn-style" type="info" @click="handleClose">取消</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { flyUserPress } from '@/api/flyNotice';
import SectionTitle from '@/components/Title';
import { mapState } from 'vuex';

export default {
  components: { SectionTitle },
  props: {
    queryOrderId: {
      type: Number,
      default: -1
    }
  },
  data() {
    return {
      ids: '',
      descriptionStr: '',
      dialogVisible: false,
      loading: false
    };
  },
  computed: {
    ...mapState({
      'showMobilePage': state => state.app.showMobilePage
    }),
    confirmDisable() {
      return this.loading || (!this.descriptionStr || !this.descriptionStr.replace(/\s/g, ''));
    }
  },
  methods: {
    openDialog(ids) {
      this.ids = ids;
      this.descriptionStr = '请及时响应询单，谢谢合作~';
      this.dialogVisible = true;
    },
    handleClose() {
      this.ids = '';
      this.descriptionStr = '';
      this.dialogVisible = false;
    },
    handleConfirm() {
      this.loading = true;
      const data = {
        ids: this.ids,
        queryOrderId: this.queryOrderId,
        descriptionStr: this.descriptionStr
      };
      flyUserPress(data).then(res => {
        this.loading = false;
        this.handleClose();
        this.$message.success('催办成功');
      }).catch(e => {
        this.loading = false;
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.dialog-footer {
  display: flex;
  justify-content: center;
  margin-top: 25px;
  .ok {
    width: 120px;
    font-size: 16px;
    padding: 8px 20px;
  }
  .cancel-btn-style {
    font-size: 14px;
    padding: 8px 20px;
    margin-left: 16px !important;
  }
}
</style>
